var host = 'http://123.56.112.56/';

function requestPost(postUrl, postData, doSuccess, doFail){
  wx.request({
    url: host + postUrl,
    data: postData,
    header:{
      'content-type': 'application/json'
    },
    method: 'POST',
    success: function(res){
      doSuccess(res.data);
    },
    fail: function(){
      doFail();
    }
  })
}

function requestGet(getUrl, getData, doSuccess, doFail) {
  wx.request({
    url: host + getUrl,
    data: getData,
    header: {
      'content-type': 'application/json'
    },
    method: 'GET',
    success: function (res) {
      doSuccess(res.data);
    },
    fail: function () {
      doFail();
    }
  })
}

function requestFile (fileUrl, filePath, doSuccess, doFile) {
  wx.uploadFile({
    url: host + fileUrl,
    filePath: filePath,
    name: 'file',
    header: {
      'content-type': 'multipart/form-data'
    },
    success: function (res) {
      doSuccess(res.data);
    },
    fail: function () {
      doFail();
    }
  })
}

module.exports = {
  requestPost: requestPost,
  requestGet: requestGet,
  requestFile: requestFile
}